package com.offcn;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class HttpClientTest {

    public static void main(String[] args) throws IOException {

        //1、创建httpclient对象
        DefaultHttpClient httpClient = new DefaultHttpClient();
        //2、get、post 创建对应的请求方法对象
        HttpGet httpGet = new HttpGet("http://www.ujiuye.com");
        //3、使用httpclient对象发出请求
        HttpResponse response = httpClient.execute(httpGet);
        //4、解析响应结果，获取响应数据
        HttpEntity entity = response.getEntity();
        //5、借助EntityUtils工具类解析响应结果
        String s = EntityUtils.toString(entity, "GBK");
        System.out.println("响应结果:"+s);


    }
}
